package com.digitalchina.lxnsy.activity.ecardConsult;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.EcardConsultVO;
import com.digitalchina.lxnsy.interfaces.ICallBackPos;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;

import java.util.ArrayList;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/3/15 14:28
 * 修改备注：
 * ================================================
 */

public class EcardConsultHolder extends BaseViewHolder<EcardConsultVO> {

    private TextView tvTime;
    private TextView tvPhone;
    private TextView tvTitle;
    private TextView tvDetail;
    private TextView tvState; // 回复按钮
    private LinearLayout layout;
    private NineGridView nineGridView;
    private ICallBackPos iCallBackPos;
    private String type;


    public EcardConsultHolder(ViewGroup parent, ICallBackPos iCallBackPos, String type) {
        super(parent, R.layout.item_ecard_consult);
        tvTime = $(R.id.tv_time);
        tvTitle = $(R.id.tv_title);
        tvPhone = $(R.id.tv_phone);
        tvState = $(R.id.tv_state);
        tvDetail = $(R.id.tv_detail);
        layout = $(R.id.layout_imgs);
        nineGridView = $(R.id.nineGrid);

        this.iCallBackPos = iCallBackPos;
        this.type = type;
    }

    @Override
    public void setData(final EcardConsultVO data) {
        super.setData(data);


        tvPhone.setText(data.getConsultUserPhone());
        tvTime.setText(data.getCreateTime());
        tvTitle.setText(data.getQuestionContent());

        if ("0".equals(type)) {
            tvState.setVisibility(View.VISIBLE);
        } else {
            tvState.setVisibility(View.GONE);
        }


        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        if (data.getConsultImgList() != null && data.getConsultImgList().size() > 0) {
//            layout.removeAllViews();
//            layout.removeAllViewsInLayout();
            nineGridView.setVisibility(View.VISIBLE);
            for (int i = 0; i < data.getConsultImgList().size(); i++) {
//                View view = LayoutInflater.from(getContext()).inflate(R.layout.view_image, null);
//                SimpleDraweeView sdv = view.findViewById(R.id.sdv_image);
//                FrescoUtil.showImageSmall(data.getFeedBackImgs().get(i).getImgID(), sdv);
//                layout.addView(view);
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(data.getConsultImgList().get(i).getImgId());
                info.setBigImageUrl(data.getConsultImgList().get(i).getImgId());
                imageInfo.add(info);
            }
        } else {
            nineGridView.setVisibility(View.GONE);
        }

        nineGridView.setAdapter(new NineGridViewClickAdapter(getContext(), imageInfo));


        tvState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iCallBackPos.clickOk(getAdapterPosition());
            }
        });

        tvDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                GotoUtil.gotoActivity((Activity) getContext(), EcardConsultDetailsActivity.class, "vo", data);
            }
        });
    }
}
